package com.example.doublepink.timedowntest;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.net.Uri;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private boolean isShow = true;
    private TextView text;
    long time = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        text = (TextView) findViewById(R.id.text);
        text.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {

                                        isShow = true;
                                        if (time>0){
                                            Log.i("time1","time1点击"+time);
                                            isShow = false;
//                                            time = 5;
                                        }else {
                                            down();
                                            Log.i("time1","time2延时"+time);
                                        }

                                        if (isShow){

                                            Log.i("time","定时5s");
                                        }


                                    }
                                }
        );

    }

    private void down() {
        time = 5;
        countDownHandler.removeCallbacks(countDownRunnable);
        countDownHandler.post(countDownRunnable);
    }

    private Handler countDownHandler = new Handler();

    private Runnable countDownRunnable = new Runnable() {
        @Override
        public void run() {

            if (time > 0) {
                time --;
                countDownHandler.postDelayed(countDownRunnable, 1000);

            } else {
                time = 0;

            }


        }
    };


}
